package org.action.inventory.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import org.action.inventory.domain.entity.ActionTicket;
import org.action.inventory.mapper.ActionTicketMapper;
import org.action.inventory.service.IActionTicketService;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zafkiel
 * @since 2025-06-21
 */
@Service
public class ActionTicketServiceImpl extends ServiceImpl<ActionTicketMapper, ActionTicket> implements IActionTicketService {

    @Override
    public boolean deductActionTicket(Integer id) {
        return baseMapper.updateActionTicket(id) > 0;
    }

    @Override
    public List<BigDecimal> getActionTicketPriceByIds(List<Integer> ids) {
        if (ids == null || ids.isEmpty()) {
            return Collections.emptyList(); // 处理空ID列表
        }

        // 使用LambdaQueryWrapper构建查询
        List<ActionTicket> priceObjects = lambdaQuery()
                .select(ActionTicket::getAcTicketPrice) // 指定查询字段
                .in(ActionTicket::getActionId, ids)    // 添加IN条件
                .list();                           // 获取单字段值列表
        System.out.println(priceObjects);
        return priceObjects.stream()
                .map(ActionTicket::getAcTicketPrice)
                .toList();
    }

    @Override
    public boolean restoreStock(Integer ticketId) {
        System.out.println("ticketId:"+ticketId);
        return baseMapper.restoreStock(ticketId) > 0;
    }

    @Override
    public void saveActionTicket(ActionTicket actionTicket) {
        baseMapper.insertOrUpdate(actionTicket);
        //将活动的可销售票数存到redis中
        //stringRedisTemplate.opsForValue().set(Action_Ticket_Inventory+actionTicket.getId(),actionTicket.getAcTicketNumber().toString());
    }
}
